<?php

namespace app\libs\SpreedlySDK\Builder;

use app\model\Orders;
use think\Request;

 class SpreedlyPurchaseBuilder
{


    public function __construct(protected Orders $order,protected Request $request)
    {
    }

    public function toArray():array
    {
        $payment_method = $this->order->payment_token;
        $transaction = [
            'amount' => intval(bcmul($this->order->total_present,"100",1)),
            'currency_code' => $this->order->present_currency,
            'email' => $this->order->email,
            'order_id' => $this->order->id,
            'description' => $this->request->header('Referer',''),
            'ip' => $this->order->ip,
            'shipping_address' => $this->setShippingAddress(),
        ];
        $transaction = array_merge($transaction, $payment_method);
        return compact('transaction');


    }

    protected function setShippingAddress()
    {
        return [
            'address1' => $this->order->shippingAddress->address1,
            'city' => $this->order->shippingAddress->city,
            'state' => $this->order->shippingAddress->province,
            'country' => $this->order->shippingAddress->country,
            'zip' => $this->order->shippingAddress->zip,
            'phone_number' => $this->order->shippingAddress->phone,
        ];
    }

}